using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace AvaloniaApplication1.ViewModels;

public class SettingsPageViewModel : INotifyPropertyChanged
{
    // 深色主题开关
    private bool _isDarkThemeEnabled = true;

    // 添加Message属性以支持绑定
    private string _message = "欢迎使用Avalonia这是设置页面";

    // 当前选择的字体大小
    private int _selectedFontSize = 12;

    // 用户名
    private string _username = "默认用户";

    public string Username
    {
        get => _username;
        set => SetField(ref _username, value);
    }

    public bool IsDarkThemeEnabled
    {
        get => _isDarkThemeEnabled;
        set => SetField(ref _isDarkThemeEnabled, value);
    }

    // 字体大小集合（必须为 public）
    public ObservableCollection<int> FontSizes { get; } = new()
    {
        10, 12, 14, 16, 18, 20
    };

    public int SelectedFontSize
    {
        get => _selectedFontSize;
        set => SetField(ref _selectedFontSize, value);
    }

    public string Message
    {
        get => _message;
        set => SetField(ref _message, value);
    }

    public event PropertyChangedEventHandler? PropertyChanged;

    protected void OnPropertyChanged([CallerMemberName] string? name = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }

    protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? name = null)
    {
        if (EqualityComparer<T>.Default.Equals(field, value)) return false;
        field = value;
        OnPropertyChanged(name);
        return true;
    }
}